package com.hhkj.api.train.model.info.req;

import cn.hutool.core.collection.CollectionUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * TrainReq
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/5/26 13:51
 */
@Data
public class TrainStageReq
{
    /** 唯一键信息 */
    @NotBlank(message = "培训代码为空")
    private String trainKey;

    /** 题目作答列表 */
    private List<AnswerReq> answerList;

    /**
     * 获取学生答案信息 根据题目id 键值对
     *
     * @return 答案信息键值
     */
    public Map<Long, String> getAnswerMapById()
    {
        return this.getAnswerList().stream()
                .collect(Collectors.groupingBy(AnswerReq::getId,
                        Collectors.collectingAndThen(Collectors.toList(),
                                answerList -> CollectionUtil.getFirst(answerList).getAnswer())));
    }
}
